import java.io.File;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;


public class LogSetup {	
	private Logger LOG;
	public LogSetup(Logger log){
		LOG = log;
	}
		
	public Logger initializeToErr(String logName){
			Logger LOG = Logger.getLogger(logName);
			LOG.setUseParentHandlers(false);
			ConsoleHandler errHandler = new ConsoleHandler();
			errHandler.setFormatter(new ErrorFormatter());
			errHandler.setLevel(Level.SEVERE);
			LOG.addHandler(errHandler);
			return LOG;

	}
	
	public boolean setInfoLog(File logDest) {//Set up info log to report file
		boolean success = true;
		try {
			FileHandler infoHandler = new FileHandler(logDest.toString());
			infoHandler.setLevel(Level.INFO);
			LOG.addHandler(infoHandler);
		} catch (SecurityException e) {
			success = false;
			LOG.severe("unable to open " + logDest.toString());
		} catch (IOException e) {
			LOG.severe("008: IO error with " + logDest.toString());//TODO
			success = false;
		}
		return success;
	}
	
	
	
	private class ErrorFormatter extends Formatter{

		@Override
		public String format(LogRecord rec) {
			
			return ("Error_Code " + rec.getMessage()+"\n");
		}

	}
}
